<%@page import="com.baozun.util.WebUtil"%>
<%@page import="com.baozun.util.CookieUtil"%>
<%@page import="java.util.Map"%>
<%@page import="java.net.CookieHandler"%>
<%@page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta charset="utf-8" />
<title>登录界面</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template."/>
<meta name="author" content=""/>
<!-- basic styles -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="assets/css/font-awesome.min.css" />
<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->

<!-- page specific plugin styles -->

<!-- fonts -->

<link rel="stylesheet" href="assets/css/font.css" />

<!-- ace styles -->

<link rel="stylesheet" href="assets/css/ace.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />

<!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->

<!-- inline styles related to this page -->

<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

<!--[if lt IE 9]>
		<script src="assets/js/html5shiv.js"></script>
		<script src="assets/js/respond.min.js"></script>
		<![endif]-->
<style>
 .registe_message{
 	font-family:'微软雅黑';
 	font-size:12px;
 	font-weight:bold;
 }
 .forget_message{
 	font-family:'微软雅黑';
 	font-size:12px;
 	font-weight:bold;
 }
 .login_message{
 	font-family:'微软雅黑';
 	font-size:12px;
 	font-weight:bold;
 }
 .alert-red{
 	color:red;
 }
.ser-signup-link .noline{
 	text-decoration:none;
 }
</style>
</head>
<%
String message = request.getParameter("message");
Map<String,Cookie> cookieMap = CookieUtil.getCookieMap(request);
%>
<body class="login-layout">
	<div class="main-container">
		<div class="main-content">
			<div class="row">
				<div class="col-sm-10 col-sm-offset-1">
					<div class="login-container">
						<div class="center">
							<h1>
								<i class="icon-leaf green"></i> <span class="red">精品</span> <span
									class="white">网络应用</span>
							</h1>
							<h4 class="blue">&copy; 万世极缘网络工作室</h4>
						</div>

						<div class="space-6"></div>

						<div class="position-relative">
							<div id="login-box"
								class="login-box visible widget-box no-border">
								<div class="widget-body">
									<div class="widget-main">
										<h4 class="header blue lighter bigger">
											<i class="icon-coffee green"></i> 登录信息&nbsp;&nbsp;&nbsp;&nbsp;<font class="login_message alert-red" id="login_message"><%=message == null?"":WebUtil.decodeURL(message) %></font>
										</h4>

										<div class="space-6"></div>

										<form id="login_submit_form" name="login_submit_form" method="post">
											<fieldset>
												<label class="block clearfix"> 
													<span class="block input-icon input-icon-right"> 
														<input id="login_username" name="stUsername" value="<%=cookieMap.containsKey("stUsername")?cookieMap.get("stUsername").getValue():"" %>"
														type="text" class="form-control" placeholder="用户名" onkeydown="enterJump(event,'login_password')"/> 
														<i class="icon-user"></i>
													</span>
												</label>
												<label class="block clearfix">
													<span class="block input-icon input-icon-right"> 
														<input id="login_password" name="stPassword" value="<%=cookieMap.containsKey("stPassword")?cookieMap.get("stPassword").getValue():"" %>" onkeydown="enterJump(event,'login_submit_form')"
														type="password" class="form-control" placeholder="密码" />
														<i class="icon-lock"></i>
													</span>
												</label>
												<div class="space"></div>
												<div class="clearfix">
													<label class="inline"> 
													<%
													boolean isRememberMe = false;
													if(cookieMap.containsKey("remember_me")){
													    isRememberMe = true;
													}
													%>
													<input type="checkbox" name="remember_me"<%if(isRememberMe){%>checked<%}%>
														class="ace" /> <span class="lbl">记住我</span>
													</label>

													<button type="button" onclick="loginCheck()"
														class="width-35 pull-right btn btn-sm btn-primary">
														<i class="icon-key"></i> 登录
													</button>
												</div>
												<div class="space-4"></div>
											</fieldset>
										</form>

										<!--< div class="social-or-login center">
												<span class="bigger-110">Or Login Using</span>
											</div>

											 <div class="social-login center">
												<a class="btn btn-primary">
													<i class="icon-facebook"></i>
												</a>

												<a class="btn btn-info">
													<i class="icon-twitter"></i>
												</a>

												<a class="btn btn-danger">
													<i class="icon-google-plus"></i>
												</a>
											</div> -->
									</div>
									<!-- /widget-main -->

									<div class="toolbar clearfix">
										<div>
											<a style="cursor: pointer;" onclick="showbox('forgot-box')"
												class="forgot-password-link"> <i class="icon-arrow-left"></i>
												忘记密码
											</a>
										</div>

										<div>
											<a style="cursor:pointer;" onclick="showbox('signup-box')"
												class="user-signup-link noline"> 注册新用户 <i
												class="icon-arrow-right"></i>
											</a>
										</div>
									</div>
								</div>
								<!-- /widget-body -->
							</div>
							<!-- /login-box -->

							<div id="forgot-box" class="forgot-box widget-box no-border">
								<div class="widget-body">
									<div class="widget-main">
										<h4 class="header red lighter bigger">
											<i class="icon-key"></i> 取回密码&nbsp;&nbsp;&nbsp;&nbsp;<font class="forget_message alert-red" id="forget_message"></font>
										</h4>
										<div class="space-6"></div>
										<p>输入邮箱</p>
										<form name="forget_password_form" method="post" action="forget_password_submit.do">
											<fieldset>
												<label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="forget_email" name="stMail"
														type="text" class="form-control" placeholder="Email" />
														<i class="icon-envelope"></i>
												</span>
												</label>
												<label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="forget_stUsername" name="stUsername"
														type="text" class="form-control" placeholder="用户名" />
														<i class="icon-user"></i>
												</span>
												</label>
												<div class="clearfix">
													<button type="button" onclick="sendMail()"
														class="width-35 pull-right btn btn-sm btn-danger">
														<i class="icon-lightbulb"></i> 发送给我们！
													</button>
												</div>
											</fieldset>
										</form>
									</div>
									<!-- /widget-main -->
									<div class="toolbar center">
										<a style="cursor: pointer;" onclick="showbox('login-box')"
											class="back-to-login-link"> 返回登录 <i
											class="icon-arrow-right"></i>
										</a>
									</div>
								</div>
								<!-- /widget-body -->
							</div>
							<!-- /forgot-box -->
							<div id="signup-box" class="signup-box widget-box no-border">
								<div class="widget-body">
									<div class="widget-main">
										<h4 class="header green lighter bigger">
											<i class="icon-group blue"></i> 新用户注册
										</h4>
										<div class="space-6"></div>
										<p>输入您的信息&nbsp;&nbsp;&nbsp;&nbsp;<font class="registe_message alert-red" id="registe_message">请填写所有信息</font></p>
										<form id="registe_form" name="registe_form" action="registe.do" method="post">
											<fieldset>
												<label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="registe_email"
														type="email" class="form-control" placeholder="电子邮箱" name="stEmail"
														onblur="checkUsable('registe_email','stEmail','registe_message','邮箱已经被注册')" onkeydown="enterJump(event,'registe_username')"/> <i
														class="icon-envelope"></i>
												</span>
												</label>
												<label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="registe_username"
														type="text" class="form-control" placeholder="用户名" name="stUsername" onkeydown="enterJump(event,'registe_name')"
														onblur="checkUsable('registe_username','stUsername','registe_message','该用户名已被使用')" /> <i
														class="icon-user"></i>
												</span>
												</label>
												<label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="registe_name" onkeydown="enterJump(event,'registe_password')"
														type="text" class="form-control" placeholder="姓名" name="stName"/> <i
														class="icon-credit-card"></i>
												</span>
												</label> <label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="registe_password" onkeydown="enterJump(event,'registe_confirm_password')"
														type="password" class="form-control" placeholder="密码" name="stPassword"/>
														<i class="icon-lock"></i>
												</span>
												</label> <label class="block clearfix"> <span
													class="block input-icon input-icon-right"> <input id="registe_confirm_password" onkeydown="enterJump(event,'registe_form')"
														type="password" class="form-control" placeholder="确认密码"/>
														<i class="icon-retweet"></i>
												</span>
												</label> <label class="block"> <input type="checkbox"
													class="ace" /> <span class="lbl"> 我接受 <a href="#">用户协议</a>
												</span>
												</label>

												<div class="space-24"></div>

												<div class="clearfix">
													<button type="reset" class="width-30 pull-left btn btn-sm">
														<i class="icon-refresh"></i> 重置
													</button>

													<button type="button" onclick="registe()"
														class="width-65 pull-right btn btn-sm btn-success">
														注册 <i class="icon-arrow-right icon-on-right"></i>
													</button>
												</div>
											</fieldset>
										</form>
									</div>

									<div class="toolbar center">
										<a style="cursor: pointer;" onclick="showbox('login-box')"
											class="back-to-login-link"> <i class="icon-arrow-left"></i>
											返回登录
										</a>
									</div>
								</div>
								<!-- /widget-body -->
							</div>
							<!-- /signup-box -->
						</div>
						<!-- /position-relative -->
					</div>
				</div>
				<!-- /.col -->
			</div>
			<!-- /.row -->
		</div>
	</div>
	<!-- /.main-container -->

	<!-- basic scripts -->

	<!--[if !IE]> -->

	<!-- <![endif]-->

	<!--[if IE]>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<![endif]-->

	<!--[if !IE]> -->
<script src='assets/js/jquery-2.0.3.min.js'></script>
<script src="assets/js/jquery.gritter.min.js"></script>
	<!-- <![endif]-->

	<!--[if IE]>
<script type="text/javascript">
 window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>

	<!-- inline scripts related to this page -->

	<script type="text/javascript">
	var canRegiste = false;
		function show_box(id) {
			jQuery('.widget-box.visible').removeClass('visible');
			jQuery('#' + id).addClass('visible');
		}
		function showbox(id){
			show_box(id); return false;
		}
	</script>
	<script type="text/javascript">
	//检查是否为空，如果为空返回假，有值返回真,提示信息为message
	function checkEmpty(id,message_id,message){
		var value = $("#"+id).val();
		if(value == null || "" == value){
			$("#"+message_id).html(message);
			canRegiste = false;
			return false;
		}else{
			canRegiste = true;
			return true;
		}
	}
//id为input输入框的id,param为要验证的属性值，message为如果不可用的提示消息
	function checkUsable(id,param,message_id,message) {
		var value=$("#"+id).val();
		if(value != null && value != ""){
			$.ajax({
				url:"check_usabled.do?"+param+"="+value,
				dataType:"text",
				type:"post",
				success:function(data, status){
					//如果返回信息为错误的
					if("right" != data){
						$("#"+message_id).html(message);
						canRegiste = false;
						return false;
					}else{
						$("#"+message_id).html("");
						canRegiste = true;
						return true;
					}
				}
			});
		}
	}
	
	//确认密码校验
	function confirmPassword(){
		var stPassword = $("#registe_password").val();
		var confirmPassword = $("#registe_confirm_password").val();
		if(confirmPassword != stPassword){
			$("#registe_message").html("确认密码不一致");
			return false;
		}else{
			return true;
		}
	}
	
	function checkEmail(id,messageid,message){
		var regex = /^[\w\.-]+?@([\w\-]+\.){1,2}[a-zA-Z]{2,3}$/;
		var email = $("#"+id).val();
		if(regex.test(email)){
			return true;
		}else{
			$("#"+id).focus();
			$("#"+messageid).html(message);
			return false;
		}
	}
	//注册信息
	function registe(){
		//注册信息提交
		if(checkEmpty("registe_email","registe_message","邮箱不能为空")
				&&checkEmail("registe_email","registe_message","邮箱填写不正确")
				&&checkEmpty("registe_username","registe_message","用户名不能为空")
				&&checkEmpty("registe_name","registe_message","姓名不能为空")
				&&checkEmpty("registe_password","registe_message","密码不能为空")
				&&checkEmpty("registe_confirm_password","registe_message","确认密码不能为空")
				&&canRegiste
				&&confirmPassword()){
			document.registe_form.action="registe.do";
			document.registe_form.submit();
		}
	}
	
	//登录提交
	function loginCheck(){
		if(checkEmpty("login_username","login_message", "用户名不能为空")	&& checkEmpty("login_password","login_message","密码不能为空")){
			document.login_submit_form.action="login_submit.do";
			document.login_submit_form.submit();
		}
	}
	
	//忘记密码的邮箱提交
	function sendMail(){
		if(checkEmpty("forget_email","forget_message","邮箱不能为空") 
				&&checkEmail("forget_email","forget_message","邮箱填写不正确")
				&& checkEmpty("forget_stUsername","forget_message","用户名不能为空")){
			var username=$("#forget_stUsername").val();
			var email = $("#forget_email").val();
			$.ajax({
				url:"forget_password_submit.do",
				data:{stUsername:username,stEmail:email},
				dataType:"text",
				success:function(data,status){
					//成功后提示邮件发送成功
					$.gritter.add({
						title: '邮件发送成功',
						text: '您的邮件已经发送，您可以登录邮箱查看并根据说明进行操作！',
						class_name: 'gritter-info gritter-center gritter-light'
					});
				},
				error:function(data){
					//失败后提示
					//成功后提示邮件发送成功
					$.gritter.add({
						title: '邮件发送失败',
						text: '可能由于网络原因或者邮箱不正确！',
						class_name: 'gritter-error gritter-center'
					});
				}
			});
		}
	}
	
	//按下enter键后跳到下一个输入框,输入完成后提交,如果得到的id是form，那么该form进行提交
	function enterJump(event,id){
		//如果是按下回车键
		if(event.keyCode == 13){
			//先判断id得到的是输入框还是form
			var obj = $("#"+id);
			var tagName = obj.prop("tagName");//注意这里不能使用attr，使用attr将会是undifined
			var name = obj.prop("name");
			if(tagName == "INPUT"){
				obj.focus();//输入框进入该输入框
			}else{
				if(name.indexOf("login")>-1){
					//登录提交
					loginCheck();
				}else if(name.indexOf("registe")>-1){
					//注册提交
					registe();
				}else if(name.indexOf("forget_password")>-1){
					//密码忘记提交
					sendMail();
				}
			}
		}
	}
</script>
</body>
</html>

